package com.liesheng.haylou.ui.main.card;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.liesheng.haylou.R;
import com.liesheng.haylou.bean.CardBean;
import com.liesheng.haylou.utils.TimeUtils;
import com.liesheng.haylou.utils.ToastUtil;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;

/**
 * Created by Android Studio.
 * User: zhangzhiqiang
 * Date: 2019/12/18
 * Time: 9:07
 */

public class CardManagerVm extends RecyclerView.Adapter<CardManagerVm.MyViewHolder> {
    private List<CardBean> list;
    private int selectedAddDel = 0;
    private int pype = 0;
    private OnItemClickListener onItemClickListener;

    public CardManagerVm(List<CardBean> list, OnItemClickListener onItemClickListener) {
        this.list = list;
        this.onItemClickListener = onItemClickListener;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView tvUserMame;
        private ImageView addDel, img_id, ivAffirm;

        public MyViewHolder(View itemView) {
            super(itemView);
            tvUserMame = itemView.findViewById(R.id.tvUserMame);
            addDel = itemView.findViewById(R.id.addDel);
            img_id = itemView.findViewById(R.id.img_id);
            ivAffirm = itemView.findViewById(R.id.ivAffirm);
        }
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_card_manager, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        CardBean msg = list.get(position);
        holder.tvUserMame.setText(msg.getUsername());
        holder.addDel.setBackgroundResource(position == selectedAddDel ? R.drawable.home_icon_cardopt_reduce : R.drawable.home_ico_cardopt_add);
        holder.img_id.setBackgroundResource(R.drawable.home_ico_sport);
        holder.ivAffirm.setBackgroundResource(R.drawable.home_ico_sort);
        holder.addDel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(view, position);

                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }


    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

}
